/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package negocio;

import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
/**
 *
 * @author Mario
 */
public class Enviar {

    private final Properties properties = new Properties();
    private Session session = null;
   
    public Enviar(){
    }

    private void init() {
        properties.put("mail.smtp.host", "smtp.gmail.com");
        properties.put("mail.smtp.starttls.enable", "true");
        properties.put("mail.smtp.port",25);
        properties.put("mail.smtp.mail.sender","marioae04@gmail.com");//emisor
        properties.put("mail.smtp.user", "marioae04");
        properties.put("mail.smtp.auth", "true");

        session = Session.getDefaultInstance(properties);
    }

     public void sendEmail(){

        init();  
        try{
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress((String)properties.get("mail.smtp.mail.sender")));
            message.addRecipient(Message.RecipientType.TO, new InternetAddress("mario_esp_1985@hotmail.com"));//receptor
            message.setSubject("Prueba Hola mundo");
            message.setText("Esto es una prueba");
            Transport t = session.getTransport("smtp");
            t.connect((String)properties.get("mail.smtp.user"), "mario6373686");
            t.sendMessage(message, message.getAllRecipients());
            t.close();
        }catch (MessagingException me){
                    me.getStackTrace();
            return;
        }

    }
    
}
